package com.sgb.goods.view.adapter.inquiry;

import android.content.Context;
import android.text.TextUtils;

import androidx.databinding.DataBindingUtil;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsItemInquiryPublishImageBinding;
import com.sgb.goods.entity.inquiry.FileItemInfoEntity;

/***
 *询价发布--上传图片的适配器
 * @author Administrator
 * by hq 2021.04.16
 */
public class PhotoAlbumAdapter extends BaseQuickAdapter<FileItemInfoEntity, BaseViewHolder> {

    private final Context mContext;
    private boolean canEnable = true;

    private static final String FILE_TYPE_RAR = ".rar";
    private static final String FILE_TYPE_ZIP = ".zip";
    private static final String FILE_TYPE_DOC = ".doc";
    private static final String FILE_TYPE_DOCX = ".docx";
    private static final String FILE_TYPE_PDF = ".pdf";
    private static final String FILE_TYPE_JPG = ".jpg";
    private static final String FILE_TYPE_PNG = ".png";
    private static final String FILE_TYPE_JPEG = ".jpeg";

    /**
     * 需要弹窗调用
     *
     * @param context 上下文
     */
    public PhotoAlbumAdapter(Context context) {
        super(R.layout.goods_item_inquiry_publish_image);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, FileItemInfoEntity item) {
        GoodsItemInquiryPublishImageBinding binding = DataBindingUtil.bind(helper.itemView);
        if (binding == null) {
            return;
        }
        String fileName = item.getFileName();
        if (!TextUtils.isEmpty(fileName)) {
            if (fileName.toLowerCase().endsWith(FILE_TYPE_RAR)) {
                Glide.with(mContext).load(R.mipmap.goods_icon_rar).into(binding.goodsImage);
            } else if (fileName.toLowerCase().endsWith(FILE_TYPE_ZIP)) {
                Glide.with(mContext).load(R.mipmap.goods_icon_zip).into(binding.goodsImage);
            } else if (fileName.toLowerCase().endsWith(FILE_TYPE_DOC)) {
                Glide.with(mContext).load(R.mipmap.goods_icon_doc).into(binding.goodsImage);
            } else if (fileName.toLowerCase().endsWith(FILE_TYPE_DOCX)) {
                Glide.with(mContext).load(R.mipmap.goods_icon_doc).into(binding.goodsImage);
            } else if (fileName.toLowerCase().endsWith(FILE_TYPE_PDF)) {
                Glide.with(mContext).load(R.mipmap.goods_icon_pdf).into(binding.goodsImage);
            } else if (fileName.toLowerCase().endsWith(FILE_TYPE_JPG) || fileName.toLowerCase().endsWith(FILE_TYPE_JPEG) || fileName.toLowerCase().endsWith(FILE_TYPE_PNG)) {
                Glide.with(mContext).load(R.mipmap.goods_icon_jpg).into(binding.goodsImage);
            } else {
                Glide.with(mContext).load(R.mipmap.goods_icon_jpg).into(binding.goodsImage);
            }
            binding.goodsTvFileName.setText(fileName);
        }
        if (canEnable) {
            helper.addOnClickListener(R.id.goods_tv_delete);
        }
    }

    public void setActionEnable(boolean isEnable) {
        canEnable = isEnable;
    }

}
